iT邦幫忙

2023 iThome 鐵人賽

DAY 24
0
Modern Web

三十天持續努力挑戰py系列 第 24

Day_24 手風琴 警報 標籤 With Bootstrap

  • 分享至 

  • xImage
  •  
  • 大家好,今天要做的跟之前那幾個bootstrap教學類似,主要是做相關的重點整理而已,還請大家多多關照。
  • 首先是手風琴 (Accordion),其主要功能是使用開關摺疊功能以隱藏更多的資訊,以下範例。
    https://ithelp.ithome.com.tw/upload/images/20230927/201621703dTbgLgr1p.png
    https://ithelp.ithome.com.tw/upload/images/20230927/20162170ARzkiCploX.png
<div class="accordion" id="accordionExample">
  <div class="accordion-item">
    <h2 class="accordion-header" id="headingOne">
      <button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
        Accordion Item #1
      </button>
    </h2>
    <div id="collapseOne" class="accordion-collapse collapse show" aria-labelledby="headingOne" data-bs-parent="#accordionExample">
      <div class="accordion-body">
        <strong>This is the first item's accordion body.</strong> It is shown by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-body</code>, though the transition does limit overflow.
      </div>
    </div>
  </div>
  <div class="accordion-item">
    <h2 class="accordion-header" id="headingTwo">
      <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
        Accordion Item #2
      </button>
    </h2>
    <div id="collapseTwo" class="accordion-collapse collapse" aria-labelledby="headingTwo" data-bs-parent="#accordionExample">
      <div class="accordion-body">
        <strong>This is the second item's accordion body.</strong> It is hidden by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-body</code>, though the transition does limit overflow.
      </div>
    </div>
  </div>
  <div class="accordion-item">
    <h2 class="accordion-header" id="headingThree">
      <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
        Accordion Item #3
      </button>
    </h2>
    <div id="collapseThree" class="accordion-collapse collapse" aria-labelledby="headingThree" data-bs-parent="#accordionExample">
      <div class="accordion-body">
        <strong>This is the third item's accordion body.</strong> It is hidden by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-body</code>, though the transition does limit overflow.
      </div>
    </div>
  </div>
</div>
  • 把data-bs-parent的屬性去掉即可達成,開啟其他時不關閉本身的效果。
    https://ithelp.ithome.com.tw/upload/images/20230927/20162170yWhnfWHKdU.png

  • 接下來介紹警告(alert)樣式,動態範例:

  • 點擊下面的按鈕以顯示警報 (使用行內樣式隱藏以開啟),然後使用內建的關閉按鈕關閉 (並銷毀) 它。
    https://ithelp.ithome.com.tw/upload/images/20230927/20162170N8B2TlqVhb.png

    <div id="liveAlertPlaceholder"></div>
    <button type="button" class="btn btn-primary" id="liveAlertBtn">Show live alert</button>
    <script>
        var alertPlaceholder = document.getElementById('liveAlertPlaceholder')
        var alertTrigger = document.getElementById('liveAlertBtn')

        function alert(message, type) {
            var wrapper = document.createElement('div')
            wrapper.innerHTML = '<div class="alert alert-' + type + ' alert-dismissible" role="alert">' + message + '<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button></div>'

            alertPlaceholder.append(wrapper)
        }

        if (alertTrigger) {
            alertTrigger.addEventListener('click', function () {
                alert('Nice, you triggered this alert message!', 'success')
            })
        }
    </script>
  • 在class那邊新增alert-(danger/primary/warning ...)已更改顏色。
  • 額外的內容:警報還可以包含其他的 HTML 元素,像是標題、段落以及分隔線以及多種ICON供你選擇。
    https://ithelp.ithome.com.tw/upload/images/20230927/20162170pN1gocJHrB.png
    https://ithelp.ithome.com.tw/upload/images/20230927/20162170qVX6c0kK74.png
<div class="alert alert-success" role="alert">
  <h4 class="alert-heading">Well done!</h4>
  <p>Aww yeah, you successfully read this important alert message. This example text is going to run a bit longer so that you can see how spacing within an alert works with this kind of content.</p>
  <hr>
  <p class="mb-0">Whenever you need to, be sure to use margin utilities to keep things nice and tidy.</p>
</div>
  • 最後,如果要移除alert的話,可以使用他們的JS達成。
    https://ithelp.ithome.com.tw/upload/images/20230927/20162170vvwXwX5sX9.pnghttps://ithelp.ithome.com.tw/upload/images/20230927/20162170y4Yo8SOJPO.png
<div class="alert alert-warning alert-dismissible fade show" role="alert">
  <strong>Holy guacamole!</strong> You should check in on some of those fields below.
  <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
  • 現在要介紹標籤 (Badges)幾種常用的功能,其中我比較覺得重要的是以下這幾個。
  • Buttons:標籤可以作為連結或按鈕的一部分,用於計數器。
  • 定位:使用通用類別調整 .badge 並將它放在連結或按鈕的角落。
    https://ithelp.ithome.com.tw/upload/images/20230927/20162170sO2kFUwNpc.png
    <button type="button" class="btn btn-primary m-1">
        Notifications <span class="badge bg-secondary">4</span>
    </button>
    <button type="button" class="btn btn-primary position-relative m-1 bg-dark ">
        Inbox
        <span class="position-absolute top-0 start-100 translate-middle badge rounded-pill bg-danger">
            99+
            <span class="visually-hidden">unread messages</span>
        </span>
    </button>

    <button type="button" class="btn btn-primary position-relative rounded-pill m-2">
        Profile
        <span
            class="position-absolute top-0 start-100 translate-middle p-2 bg-danger border border-light rounded-circle">
            <span class="visually-hidden">New alerts</span>
        </span>
    </button>

上一篇
Day_23 篡改猴 Tampermonkey 基礎用法教學
下一篇
Day_25 RDBMS 關聯式資料庫 基本使用教學
系列文
三十天持續努力挑戰py30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言